package com.coderman.infosys.auth.app.facadeimpl.role;

import com.coderman.infosys.auth.domain.enums.errors.RoleErrorEnum;
import com.coderman.infosys.auth.app.convert.RoleConvert;
import com.coderman.infosys.auth.domain.bo.role.RoleBO;
import com.coderman.infosys.auth.domain.gataway.UserRoleQueryGataway;
import com.coderman.infosys.auth.domain.repository.UserRoleRepository;
import com.coderman.infosys.plat.auth.common.dto.PageDTO;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import com.coderman.infosys.plat.auth.common.page.PageBO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.coderman.infosys.auth.api.dto.role.RoleDTO;
import java.util.List;
import com.coderman.infosys.auth.api.facade.role.RoleQueryFacade;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * @Description:接口实现类
 * @Author：
 * @CreateTime：2022-01-02 15:27:39
 * @version v1.0
 */
@Service
public class RoleQueryFacadeImpl   implements RoleQueryFacade{

	private  Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private UserRoleQueryGataway userRoleQueryGataway;

    @Autowired
    private UserRoleRepository userRoleRepository;


    @Override
    public ResultDataDto<PageDTO> getRolePageList(PageDTO pageDTO){
        PageBO pageBO = pageDTO.convertToBO();
        List<RoleBO> roleBOList = userRoleQueryGataway.getRolePageList(pageBO);
        List<RoleDTO> roleDTOList = RoleConvert.INSTANCE.roleBOs2dtoList(roleBOList);
        return ResultDataDto.success(pageDTO.initData(roleDTOList,pageBO.getTotalRows()));

    }

    @Override
    public ResultDataDto<RoleDTO> getByRoleCode(String roleCode){
        RoleBO roleBO = userRoleRepository.getByRoleCode(roleCode);
        if(roleBO == null){
            return ResultDataDto.fail(RoleErrorEnum.ROLE_NOT_FUND);
        }
        return  ResultDataDto.success(RoleConvert.INSTANCE.bo2dto(roleBO));
    }

    @Override
    public ResultDataDto<List<RoleDTO>> search(String search){
        List<RoleBO> roleBOList = userRoleQueryGataway.searchRole(search);
        return  ResultDataDto.success(RoleConvert.INSTANCE.roleBOs2dtoList(roleBOList));
    }

}